package modele.cases;

import modele.agent.AgentInterface;

public class Case implements CaseInterface {

	private int x, y;
	private Cases casesAround;
	private AgentInterface agent;
	@Override
	public AgentInterface getAgent() {
		return agent;
	}

	public Case(int coordX, int coordY, AgentInterface agent) {
		casesAround = new Cases();
		this.x = coordX;
		this.y = coordY;
		this.agent = agent;
		this.agent.setAgentCase(this);
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	@Override
	public int getNbAliveAround() {
		int aliveAround = 0;
		for (CaseInterface cas : casesAround.getCases()) {
			if (cas.hasAliveAgent())
				aliveAround++;
		}
		return aliveAround;
	}

	@Override
	public boolean hasAliveAgent() {

		return agent.isAlive();
	}

	@Override
	public void giveNeighbour(int i, CaseInterface neighbour) {
		casesAround.put(i, neighbour);

	}

}
